
package com.android.formula.task;

import java.util.ArrayList;

import android.content.Context;

import com.android.formula.common.MyApplication;
import com.android.formula.dao.FormulaDao;
import com.android.formula.database.SQLiteTable;
import com.android.formula.model.Formula;
import com.android.formula.model.TypeSubSubject;
import com.android.formula.utils.Constants;

/**
 * Get a Spot by Id
 */
public class GetFormulaDBTask extends
        BaseDatabaseTask<TypeSubSubject, ArrayList<Formula>> {

    public GetFormulaDBTask(Context context, TypeSubSubject param,
            IDataEventHandler<ArrayList<Formula>> dataEventHandler) {
        super(context, param, null, dataEventHandler);
    }

    @Override
    protected ArrayList<Formula> execute() {
        SQLiteTable sqlt = MyApplication.getSqLiteTable();
        if (sqlt == null || mRequestParams == null) {
            return null;
        }

        sqlt.open();
        FormulaDao dao = new FormulaDao(Formula.class, mContext,
                sqlt.getDatabase());
        ArrayList<Formula> list = dao.getItemsFromId(
                Constants.TABLE_FOMULA_COL_SS_SUBJECTID,
                "" + mRequestParams.getSsSubjectId());
        sqlt.close();
        if (!list.isEmpty()) {
            return list;
        } else {
            return null;
        }
    }
}
